<script setup name="iconselect">
import { ref } from 'vue'
import * as iconList from '@element-plus/icons-vue'
defineProps({
  modelValue: String,
})

const icons = ref(Object.keys(iconList))

const emit = defineEmits(['update:modelValue'])
const handleChange = icon => {
  emit('update:modelValue', icon)
}
</script>

<template>
  <div class="flex items-center icon-select">
    <el-select filterable :modelValue="modelValue" placeholder="请选择图标" @change="handleChange">
      <el-option v-for="item in icons" :key="item" :label="item" :value="item">
        <div class="icon-select-body">
          <span class="text-gray-500">{{ item }}</span>
          <el-icon size="18">
            <component :is="item" />
          </el-icon>
        </div>
      </el-option>
    </el-select>
    <el-icon :size="20" v-if="modelValue">
      <component :is="modelValue" />
    </el-icon>
  </div>
</template>

<style lang="scss" scoped>
.icon-select {
  display: flex;
  align-items: center;
  .el-select {
    width: 100%;
  }
  &-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .el-icon {
    margin-left: 4px;
  }
}
</style>